package com.service.impl;

import com.dto.AttendeeDTO;
import com.mapper.AttendeeMapper;
import com.mapper.UserMapper;
import com.pojo.Attendee;
import com.pojo.User;
import com.service.AttendeeService;
import com.vo.AttendeeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AttendeeServiceImpl implements AttendeeService {

    @Autowired
    private AttendeeMapper attendeeMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public boolean insertAttendee(Attendee attendee) {

        Attendee temp = attendeeMapper.getAttendee(attendee.getUserid(),attendee.getMeetingid());

        if (temp == null){
            attendeeMapper.insertAttendee(attendee);
            return true;
        } else{
            return false;
        }
    }

    @Override
    public List<AttendeeDTO> getAttendeeList(AttendeeVO attendeeVO,
                                             Integer pageSize) {
        Map<String, Object> map = new HashMap<>();
        map.put("mid",attendeeVO.getMid());
        map.put("checkStatus",attendeeVO.getCheckStatus());
        map.put("readStatus",attendeeVO.getReadStatus());
        map.put("currentPageNo",(attendeeVO.getPageIndex()-1)*pageSize);
        map.put("pageSize",pageSize);
        return attendeeMapper.getAttendeeList(map);
    }

    @Override
    public int updateByPrimaryKeySelective(Attendee attendee) {
        return attendeeMapper.updateByPrimaryKeySelective(attendee);
    }

    @Override
    public int getAttendeeCount(Integer mid, String readStatus, String checkStatus) {
        return attendeeMapper.getAttendeeCount(mid, readStatus, checkStatus);
    }

    @Override
    @Transactional(readOnly = true)
    public List<User> getStaffList() {
        // 数据转换
        Map<String, Object> conditions=new HashMap<String, Object>();

        conditions.put("role", 1);
        conditions.put("status",1);

        return userMapper.getUserList(conditions);
    }
}
